home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / SWAB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  896 b   |  23 lines

  1. /* swab.c, from p.161 of Turbo C Bible  */
  2. /* Takes an array of bytes and swaps contents of each pair of adjacent bytes. */
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. main(int argc, char **argv)
  7. {
  8.     size_t len;
  9.     char src[80], dst[80];
  10.     if (argc < 2)              /* Make sure there are two argument    */
  11.     {
  12.         printf("Usage: %s <srting ofr \"swab\">\n", argv[0]);
  13.         abort();
  14.     }
  15.     len = 2*(strlen(argv[1])/2);/* Take an even number of characters  */
  16.     strncpy(src, argv[1], len); /*                and feed it to swab */
  17.     src[len] = '\0';            /* Mark the end of string in          */
  18.     dst[len] = '\0';            /*             source and destination */
  19.     swab(src, dst, len);        /* Now copy after swapping            */
  20.     printf("Input string to \"swab\": %s\n "
  21.             "Output string to \"swab\": %s\n", src, dst);
  22.                     /*             adjacent bytes */
  23. }